// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init()

const db = cloud.database()
const _ = db.command

// 云函数入口函数
exports.main = async(event, context) => {
  result = await db.collection('concert').where({
      _id: event.concertid
    }).get()
  event.data = result.data[0]
  console.log(event.data)
  try {
    return await db.collection('tickets').add({
      // data 字段表示需新增的 JSON 数据
      data: {
        concertid: event.data._id,
        md5: "",
        starttime: event.data.starttime,
        location:event.data.location,
        title: event.data.name,
        userid: event.userid
      }
    })
  } catch (e) {
    console.error(e)
  }
}